package com.ckzp.plugins.datalist.active;

import com.ckzp.core.util.StringUtil;

import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.List;
import java.util.ArrayList;

/**
 * Filename: Active.java
 * Ttitle:   ������
 * Description:
 * Copyright:    Copyright (c) 2001-2004 BlueStar,Inc.All Rights Reserved.
 * Company:     huott
 * Author:      <a href="mailto:lanxingsc@163.com">wuyang</a>
 * Telephone:   86-28-85239210
 * Date: 2004-7-15
 * Time: 10:46:44
 * Version: 2.0.0
 */
abstract class Active {

    /**
     * ֻ�����
     */
    protected boolean tag = true;
    /**
     * ��־
     */


    protected Connection conn;

    /**
     * �Ƿ���ʾΪ��
     */
    protected boolean canNull = false;

    /**
     * �Ƿ�ֻ����ʾ
     */
    protected boolean readOnly = false;

    /**
     * �¼�
     */
    protected String event = "";

    /**
     * Ĭ��ֵ
     */
    protected String defaultStr = "";

    /**
     * ����Դ
     */
    protected String source = "";

    /**
     * �ؼ�����
     */
    protected String name = "";
    protected String id = "";
    /**
     * ��ǰֵ
     */
    protected String currentValue = "";
    /**
     * �����б�
     */
    protected List dataList = null;

    /**
     * ��ʾ�ɫ
     */
    protected String[] showColor = new String[1];
    /**
     * ��ʾ�ȼ�ɫ
     */
    protected String[] levelColor = new String[1];

    /**
     * ��ʾ��ʽ
     */

    protected String style = "";
    protected String selected_style = "";
    protected String styleclass = "";
    protected String selected_styleclass = "";

    /**
     * ��ʾÿ����
     * ����ʾN����¼���Զ�����
     * 0���ʾ�����С�
     */
    protected int brSize = 0;


    public boolean isReadOnly() {
        return readOnly;
    }

    public void setReadOnly(boolean readOnly) {
        this.readOnly = readOnly;
    }

    public void setSource(String sourceStr) {
        this.source = sourceStr;
    }


    public void setCanNull(boolean canNull) {
        this.canNull = canNull;
    }


    public void setDefaultString(String def) {
        this.defaultStr = def;
    }

    public void setShowColor(String showColor) {
        this.showColor = StringUtil.split(showColor, "`");
    }

    public Active setName(String name) {
        this.name = name;
        return this;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public void addEvent(String event) {
        this.event = this.event + event;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public List getDataList() {
        return dataList;
    }

    public void setDataList(List dataList) {
        this.dataList = dataList;
    }

    public int getBrSize() {
        return brSize;
    }

    public void setBrSize(int brSize) {
        this.brSize = brSize;
    }

    public String getSelected_style() {
        return selected_style;
    }

    public void setSelected_style(String selected_style) {
        this.selected_style = selected_style;
    }

    public void setLevelColor(String levelColor) {
        this.levelColor = StringUtil.split(levelColor, "`");
    }

    public void setStyleClass(String styleclass) {

    }

    public void doAction() {
        if (dataList == null) dataList = new ArrayList();
        if (source == null || source.length() < 1)
            return;
        long bt = System.currentTimeMillis();
        Statement st = null;
        ResultSet rs = null;
        List ll = StringUtil.splitList(source, "`");
        if (ll != null) {
            if (ll.size() > 1) {
                for (int k = 0; k < ll.size(); k += 2) {
                    String s = String.valueOf(ll.get(k));
                    String s1 = (k >= ll.size() - 1) ? "" : String.valueOf(ll.get(k + 1));
                    dataList.add(new String[]{s, s1});
                }
            }
        }
        if (dataList.size() > 0) {
            return;
        }
        dataList = new ArrayList();
    }

    /**
     * ��ʾhtml
     *
     * @param str
     * @return
     */
    public String showHtml(String str) {
        this.currentValue = str;
        return showHtml();
    }

    /**
     * ��ʾhtml
     *
     * @param i
     * @return
     */
    public String showHtml(int i) {
        this.currentValue = String.valueOf(i);
        return showHtml();
    }

    /**
     * ��ʾhtml
     *
     * @param str
     * @return
     */
    public String showNoColorHtml(String str) {
        this.currentValue = str;
        return showNoColorHtml();
    }


    public void setSelected_styleclass(String selected_styleclass) {
        this.selected_styleclass = selected_styleclass;
    }

    public void setStyleclass(String styleclass) {
        this.styleclass = styleclass;
    }

    /**
     * ��ʾhtml
     *
     * @param i
     * @return
     */
    public String showNoColorHtml(int i) {
        this.currentValue = String.valueOf(i);
        return showNoColorHtml();
    }


    /**
     * ����ʵ��
     *
     * @return
     */
    abstract String showHtml();

    /**
     * ����ʵ��
     *
     * @return
     */
    abstract String showNoColorHtml();
}
